/**
 * Mock data for application model
 * This file provides mock data for development and testing purposes
 */

/**
 * Mock business objects representing your data model entities
 */
export const mockBusinessObjects = [
  {
    name: 'Customer',
    displayName: '客户',
    keyProperty: 'id',
    properties: [
      {
        name: 'id',
        displayName: 'ID',
        type: 'number',
        isKey: true,
        isVisible: false
      },
      {
        name: 'name',
        displayName: '名称',
        type: 'string',
        isRequired: true
      },
      {
        name: 'phone',
        displayName: '电话',
        type: 'string'
      },
      {
        name: 'email',
        displayName: '邮箱',
        type: 'string',
        validationRules: [
          {
            type: 'email',
            message: '请输入有效的邮箱地址'
          }
        ]
      },
      {
        name: 'address',
        displayName: '地址',
        type: 'string'
      },
      {
        name: 'createdAt',
        displayName: '创建时间',
        type: 'datetime',
        isReadOnly: true
      }
    ]
  },
  {
    name: 'Product',
    displayName: '产品',
    keyProperty: 'id',
    properties: [
      {
        name: 'id',
        displayName: 'ID',
        type: 'number',
        isKey: true,
        isVisible: false
      },
      {
        name: 'name',
        displayName: '产品名称',
        type: 'string',
        isRequired: true
      },
      {
        name: 'code',
        displayName: '产品编码',
        type: 'string',
        isRequired: true
      },
      {
        name: 'price',
        displayName: '价格',
        type: 'number',
        format: '¥ {0:n2}',
        isRequired: true
      },
      {
        name: 'description',
        displayName: '描述',
        type: 'string',
        editorType: 'textarea'
      },
      {
        name: 'categoryId',
        displayName: '类别',
        type: 'number',
        lookupDataSource: 'Category',
        lookupDisplayProperty: 'name'
      },
      {
        name: 'isActive',
        displayName: '是否启用',
        type: 'boolean',
        defaultValue: true
      }
    ]
  },
  {
    name: 'Category',
    displayName: '产品类别',
    keyProperty: 'id',
    properties: [
      {
        name: 'id',
        displayName: 'ID',
        type: 'number',
        isKey: true,
        isVisible: false
      },
      {
        name: 'name',
        displayName: '类别名称',
        type: 'string',
        isRequired: true
      },
      {
        name: 'description',
        displayName: '描述',
        type: 'string'
      },
      {
        name: 'parentId',
        displayName: '父级类别',
        type: 'number',
        lookupDataSource: 'Category',
        lookupDisplayProperty: 'name'
      }
    ]
  },
  {
    name: 'Order',
    displayName: '订单',
    keyProperty: 'id',
    properties: [
      {
        name: 'id',
        displayName: 'ID',
        type: 'number',
        isKey: true,
        isVisible: false
      },
      {
        name: 'orderNumber',
        displayName: '订单编号',
        type: 'string',
        isReadOnly: true
      },
      {
        name: 'customerId',
        displayName: '客户',
        type: 'number',
        isRequired: true,
        lookupDataSource: 'Customer',
        lookupDisplayProperty: 'name'
      },
      {
        name: 'orderDate',
        displayName: '订单日期',
        type: 'datetime',
        defaultValue: 'now'
      },
      {
        name: 'status',
        displayName: '状态',
        type: 'enum',
        enumValues: [
          { value: 'new', displayValue: '新建' },
          { value: 'processing', displayValue: '处理中' },
          { value: 'shipped', displayValue: '已发货' },
          { value: 'delivered', displayValue: '已交付' },
          { value: 'cancelled', displayValue: '已取消' }
        ],
        defaultValue: 'new'
      },
      {
        name: 'totalAmount',
        displayName: '总金额',
        type: 'number',
        format: '¥ {0:n2}',
        isReadOnly: true
      }
    ],
    associations: [
      {
        name: 'orderItems',
        displayName: '订单项',
        targetType: 'OrderItem',
        associationType: 'collection',
        keyProperty: 'orderId'
      }
    ]
  },
  {
    name: 'OrderItem',
    displayName: '订单项',
    keyProperty: 'id',
    properties: [
      {
        name: 'id',
        displayName: 'ID',
        type: 'number',
        isKey: true,
        isVisible: false
      },
      {
        name: 'orderId',
        displayName: '订单',
        type: 'number',
        isRequired: true,
        lookupDataSource: 'Order',
        lookupDisplayProperty: 'orderNumber'
      },
      {
        name: 'productId',
        displayName: '产品',
        type: 'number',
        isRequired: true,
        lookupDataSource: 'Product',
        lookupDisplayProperty: 'name'
      },
      {
        name: 'quantity',
        displayName: '数量',
        type: 'number',
        isRequired: true,
        defaultValue: 1
      },
      {
        name: 'unitPrice',
        displayName: '单价',
        type: 'number',
        format: '¥ {0:n2}',
        isRequired: true
      },
      {
        name: 'amount',
        displayName: '金额',
        type: 'number',
        format: '¥ {0:n2}',
        isReadOnly: true,
        calculation: '{quantity} * {unitPrice}'
      },
      {
        name: 'discount',
        displayName: '折扣率',
        type: 'number',
        format: '{0}%',
        defaultValue: 0
      }
    ]
  }
];

/**
 * Mock views for displaying and editing data
 */
export const mockViews = [
  // List views
  {
    name: 'CustomerListView',
    displayName: '客户列表',
    objectType: 'Customer',
    viewType: 'list',
    columns: ['name', 'phone', 'email', 'address'],
    sortBy: { field: 'name', direction: 'asc' },
    actions: ['New', 'Edit', 'Delete', 'Refresh']
  },
  {
    name: 'ProductListView',
    displayName: '产品列表',
    objectType: 'Product',
    viewType: 'list',
    columns: ['name', 'code', 'price', 'categoryId', 'isActive'],
    filter: 'isActive eq true',
    sortBy: { field: 'name', direction: 'asc' },
    actions: ['New', 'Edit', 'Delete', 'Refresh']
  },
  {
    name: 'CategoryListView',
    displayName: '产品类别列表',
    objectType: 'Category',
    viewType: 'list',
    columns: ['name', 'description', 'parentId'],
    sortBy: { field: 'name', direction: 'asc' },
    actions: ['New', 'Edit', 'Delete', 'Refresh']
  },
  {
    name: 'OrderListView',
    displayName: '订单列表',
    objectType: 'Order',
    viewType: 'list',
    columns: ['orderNumber', 'customerId', 'orderDate', 'status', 'totalAmount'],
    sortBy: { field: 'orderDate', direction: 'desc' },
    actions: ['New', 'Edit', 'Delete', 'Refresh', 'CustomOrderAction']
  },
  
  // Detail views
  {
    name: 'CustomerDetailView',
    displayName: '客户详情',
    objectType: 'Customer',
    viewType: 'detail',
    groups: [
      {
        name: 'customerInfo',
        displayName: '基本信息',
        items: ['name', 'phone', 'email', 'address']
      },
      {
        name: 'customerAudit',
        displayName: '审计信息',
        items: ['createdAt']
      }
    ],
    actions: ['Save', 'Cancel']
  },
  {
    name: 'ProductDetailView',
    displayName: '产品详情',
    objectType: 'Product',
    viewType: 'detail',
    groups: [
      {
        name: 'productInfo',
        displayName: '基本信息',
        items: ['name', 'code', 'price', 'categoryId', 'isActive']
      },
      {
        name: 'productDetails',
        displayName: '详细信息',
        items: ['description']
      }
    ],
    actions: ['Save', 'Cancel']
  },
  {
    name: 'CategoryDetailView',
    displayName: '产品类别详情',
    objectType: 'Category',
    viewType: 'detail',
    groups: [
      {
        name: 'categoryInfo',
        displayName: '基本信息',
        items: ['name', 'description', 'parentId']
      }
    ],
    actions: ['Save', 'Cancel']
  },
  {
    name: 'OrderDetailView',
    displayName: '订单详情',
    objectType: 'Order',
    viewType: 'detail',
    groups: [
      {
        name: 'orderInfo',
        displayName: '订单信息',
        items: ['orderNumber', 'customerId', 'orderDate', 'status', 'totalAmount']
      }
    ],
    nestedViews: [
      {
        name: 'orderItems',
        displayName: '订单项',
        association: 'orderItems',
        viewName: 'OrderItemListView'
      }
    ],
    actions: ['Save', 'Cancel', 'CustomOrderAction']
  },
  {
    name: 'OrderItemListView',
    displayName: '订单项列表',
    objectType: 'OrderItem',
    viewType: 'list',
    columns: ['productId', 'quantity', 'unitPrice', 'amount', 'discount'],
    actions: ['New', 'Edit', 'Delete']
  },
  {
    name: 'OrderItemDetailView',
    displayName: '订单项详情',
    objectType: 'OrderItem',
    viewType: 'detail',
    groups: [
      {
        name: 'orderItemInfo',
        displayName: '基本信息',
        items: ['productId', 'quantity', 'unitPrice', 'amount', 'discount']
      }
    ],
    actions: ['Save', 'Cancel']
  }
];

/**
 * Mock navigation structure
 */
export const mockNavigation = {
  items: [
    {
      id: 'sales',
      displayName: '销售管理',
      icon: 'shopping-cart',
      items: [
        {
          id: 'customers',
          displayName: '客户管理',
          viewName: 'CustomerListView'
        },
        {
          id: 'orders',
          displayName: '订单管理',
          viewName: 'OrderListView'
        }
      ]
    },
    {
      id: 'products',
      displayName: '产品管理',
      icon: 'appstore',
      items: [
        {
          id: 'productList',
          displayName: '产品列表',
          viewName: 'ProductListView'
        },
        {
          id: 'categories',
          displayName: '产品类别',
          viewName: 'CategoryListView'
        }
      ]
    }
  ]
};

/**
 * Complete application mock model
 */
export const mockModel = {
  applicationName: 'Mini XAF 示例应用',
  version: '1.0.0',
  businessObjects: mockBusinessObjects,
  views: mockViews,
  navigation: mockNavigation
};
